package com.dao;

import com.entity.Td_punished;
import org.hibernate.query.NativeQuery;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface Td_punishedDao extends JpaRepository<Td_punished,Integer> {

    /**
     * 根据用户名模糊查询处分统计
     * @param name 用户名
     * @return 0=用户id   1=组织名    2=用户名  3=头像    4=处分数
     */
    @Query(value = "SELECT\n" +
            "	b.Fd_LoginID,\n" +
            "	b.fd_branchName,\n" +
            "	b.Fd_UserName,\n" +
            "	b.Fd_ImageUrl,\n" +
            "	COUNT (a.fd_disposerName) AS 'cishu'\n" +
            "FROM\n" +
            "	td_punished a,\n" +
            "	TD_tblPartyOrgMembers b\n" +
            "WHERE\n" +
            "	a.fd_punishedId = b.Fd_LoginID\n" +
            "AND b.Fd_UserName LIKE ?\n" +
            "GROUP BY\n" +
            "	b.Fd_LoginID,\n" +
            "	b.fd_branchName,\n" +
            "	b.Fd_UserName,\n" +
            "	b.Fd_ImageUrl",nativeQuery = true)
    public List<Object[]> getByName(String name, Pageable pageable);

    /**
     * 查询用户的处分数量
     * @param loginId 用户id
     * @return
     */
    @Query(value = "select count(*) from td_punished where fd_punishedId=?",nativeQuery = true)
    public int countByFd_punishedId(int loginId);

    /**
     * 根据用户名id查询处分
     * @param loginId 用户id
     * @return 0=用户id   1=组织名    2=用户名  3=头像    4=处分数
     */
    @Query(value = "select fd_punishedId,fd_type,fd_punishedName,fd_response from td_punished where fd_punishedId=?",nativeQuery = true)
    public List<Object[]> getByloginId(int loginId, Pageable pageable);
}
